<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>localStoreTest</title>
</head>

<body>

</body>
<script>
    //localStorage关闭页面还能保存，sessionStorage关闭页面就保存不了，但是刷新页面还可以保存
    if (!localStorage.getItem("l1")) {
        localStorage.setItem("l1", new Date());
    }
    if (!sessionStorage.getItem("s1")) {
        sessionStorage.setItem("s1", new Date());
    }

    console.log(
        'localStorage',
        localStorage.getItem("l1")
    );
    console.log(
        'sessionStorage',
        sessionStorage.getItem("s1")
    );
</script>

</html>